﻿<template>
  <div class="l-rblock l-form-viewer" style="padding: 8px">
    <el-form
      :model="formData"
      :rules="rules"
      size="mini"
      labelPosition="right"
      labelWidth="80px"
      ref="form"
    >
      <div class="l-auto-window only-tabs">
        <el-tabs v-model="activeName" type="card">
          <el-tab-pane
            class="l-tabs-container"
            :label="$t('主表信息')"
            name="tab0"
          >
            <el-row :gutter="0">
              <div class="l-rblock">
                <el-col
                  v-if="lr_formLookAuth('case_erp_warehouselog_f_Number')"
                  :span="24"
                >
                  <el-form-item
                    :label="$t('仓库编码')"
                    prop="case_erp_warehouselog_f_Number"
                  >
                    <l-code
                      size="mini"
                      code="erp_warehouse_num"
                      v-model="formData.case_erp_warehouselog_f_Number"
                    />
                  </el-form-item>
                </el-col>
                <el-col
                  v-if="lr_formLookAuth('case_erp_warehouselog_f_Name')"
                  :span="24"
                >
                  <el-form-item
                    :label="$t('仓库名称')"
                    prop="case_erp_warehouselog_f_Name"
                  >
                    <el-input
                      :disabled="
                        !lr_formEditAuth(
                          'case_erp_warehouselog_f_Name',
                          isReadOnly
                        )
                      "
                      v-model="formData.case_erp_warehouselog_f_Name"
                      :placeholder="$t('please enter')"
                    >
                    </el-input>
                  </el-form-item>
                </el-col>
                <el-col
                  v-if="lr_formLookAuth('case_erp_warehouselog_f_Address')"
                  :span="24"
                >
                  <el-form-item
                    :label="$t('仓库地址')"
                    prop="case_erp_warehouselog_f_Address"
                  >
                    <el-input
                      :disabled="
                        !lr_formEditAuth(
                          'case_erp_warehouselog_f_Address',
                          isReadOnly
                        )
                      "
                      v-model="formData.case_erp_warehouselog_f_Address"
                      :placeholder="$t('please enter')"
                    >
                    </el-input>
                  </el-form-item>
                </el-col>
                <el-col
                  v-if="lr_formLookAuth('case_erp_warehouselog_f_Person')"
                  :span="24"
                >
                  <el-form-item
                    :label="$t('负责人')"
                    prop="case_erp_warehouselog_f_Person"
                  >
                    <l-user-select
                      :disabled="
                        !lr_formEditAuth(
                          'case_erp_warehouselog_f_Person',
                          isReadOnly
                        )
                      "
                      v-model="formData.case_erp_warehouselog_f_Person"
                    />
                  </el-form-item>
                </el-col>
                <el-col
                  v-if="lr_formLookAuth('case_erp_warehouselog_f_Phone')"
                  :span="24"
                >
                  <el-form-item
                    :label="$t('手机号')"
                    prop="case_erp_warehouselog_f_Phone"
                  >
                    <el-input
                      :disabled="
                        !lr_formEditAuth(
                          'case_erp_warehouselog_f_Phone',
                          isReadOnly
                        )
                      "
                      v-model="formData.case_erp_warehouselog_f_Phone"
                      :placeholder="$t('please enter')"
                    >
                    </el-input>
                  </el-form-item>
                </el-col>
                <el-col
                  v-if="lr_formLookAuth('case_erp_warehouselog_f_Description')"
                  :span="24"
                >
                  <el-form-item
                    :label="$t('备注')"
                    prop="case_erp_warehouselog_f_Description"
                  >
                    <el-input
                      type="textarea"
                      :disabled="
                        !lr_formEditAuth(
                          'case_erp_warehouselog_f_Description',
                          isReadOnly
                        )
                      "
                      :rows="10"
                      v-model="formData.case_erp_warehouselog_f_Description"
                      :placeholder="$t('please enter')"
                    />
                  </el-form-item>
                </el-col>
              </div>
            </el-row>
          </el-tab-pane>
        </el-tabs>
      </div>
    </el-form>
  </div>
</template>
<script>
const api = window.$api.erpcase.warehouselog;

export default {
  props: {
    isReadOnly: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      moduleCode: "ERP_Warehouse",
      activeName: "tab0",
      formData: {
        case_erp_warehouselog_f_Number: "", // 仓库编码
        case_erp_warehouselog_f_Name: "", // 仓库名称
        case_erp_warehouselog_f_Address: "", // 仓库地址
        case_erp_warehouselog_f_Person: "", // 负责人
        case_erp_warehouselog_f_Phone: "", // 手机号
        case_erp_warehouselog_f_Description: "", //备注
      },
      rules: {
        case_erp_warehouselog_f_Name: [
          { required: true, message: "please enter仓库名称" },
        ],
        case_erp_warehouselog_f_Address: [
          { required: true, message: "please enter仓库地址" },
        ],
        case_erp_warehouselog_f_Person: [
          { required: true, message: "please select负责人" },
        ],
        case_erp_warehouselog_f_Phone: [
          {
            required: true,
            pattern:
              /^(13[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\d{8}$/,
            message: "please enter手机号",
          },
        ],
      },
    };
  },
  computed: {
    case_erp_warehouselog_f_MaterialIdOptions() {
      const data = this.lr_DataSource("ERP_Materials");
      return this.lr_DataSourceOptions(data, "f_id", "f_name");
    },
  },
  methods: {
    // Reset表单
    resetForm() {
      this.$formClear(this.$refs.form);
      this.activeName = "tab0";
    },
    // 校验表单
    async validateForm() {
      if (!(await this.$formValidateWraper(this.$refs.form))) {
        return false;
      }

      return true;
    },
    // 设置表单数据
    setForm(data) {
      this.$setFormData(this.formData, data, "case_erp_warehouselog");
    },
    // 获取表单数据
    getForm() {
      return this.$getFormData(this.formData, "case_erp_warehouselog");
    },

    async loadFormData({ keyValue /*,params,node*/ }) {
      //  keyValue 流程中相当于流程processId,params 传递参数,node 流程节点
      const data = await this.$awaitWraper(api.get(keyValue));
      if (data) {
        this.setForm(data);
        return true;
      } else {
        return false;
      }
    },

    async saveForm({ keyValue, isEdit /*,code,node*/ }) {
      // isEdit 是否更新数据, keyValue 流程中相当于流程processId,code 表示流程中的操作码,node 流程节点
      const postData = this.getForm();
      if (isEdit) {
        // Edit
        return await this.$awaitWraper(api.update(keyValue, postData));
      } else {
        // Add
        postData.f_Id = keyValue;

        return await this.$awaitWraper(api.add(postData));
      }
    },
  },
};
</script>